import { commonIndexConfig, ListComponentsConfig, DetailComponentsConfig, FormListConfig, TableHeaderConfig, AnchorConfig } from '@/typings';

import apiUrl from '@/api/config-center/channelOrganization';
import { channelSearchConfig } from '@/layout-components/vip-dialog/config';

import commonApiUrl from '@/api/common-api/index';
import { Tools } from '@/utils/tools';
interface ChannelDetail {
    channelProperties: FormListConfig[];
    financialInformation: FormListConfig[];
    mallField: FormListConfig[];
    salePolicy: FormListConfig[];
    anchorConfig: AnchorConfig[];
    address: TableHeaderConfig[];

    // barcodeInfo: TableHeaderConfig[]
}
export const layoutConfigs: commonIndexConfig = {
    tabs: [
        {
            label: '列表',
            value: 'list',
            lang: 'layout.tabs.list'
        },
        {
            label: '详情',
            value: 'detail',
            lang: 'layout.tabs.detail'
        }
    ]
};

export const listConfig: ListComponentsConfig = {
    btns: [
        {
            name: '新建渠道',
            value: 'add',
            operationId: 'create',
            lang: 'layout.btns.addChannel',
            event: 'add',
            id: 'btn_g_d_blue',
            plain: true,
            icon: 'el-icon-plus',
            interface: {
                name: 'add'
            }
        },
        {
            name: '审核',
            value: 'batchAudit',
            lang: 'layout.btns.batchAudit',
            event: 'batch-audit',
            operationId: 'check',
            id: 'btn_g_gray',
            plain: true,
            interface: {
                name: 'batch-audit',
                apiUrl: apiUrl.auditChannel
            }
        },
        {
            name: '删除',
            value: 'batchDelete',
            lang: 'layout.btns.batchDelete',
            event: 'batch-delete',
            operationId: 'delete',
            id: 'btn_g_red',
            plain: true,
            interface: {
                name: 'batch-delete',
                apiUrl: apiUrl.delChannel
            }
        },
        {
            name: '导入',
            value: 'batchImport',
            lang: 'layout.btns.batchImport',
            event: 'batch-import',
            operationId: 'import',
            id: 'btn_g_gray',
            plain: true,
            interface: {
                name: 'batch-import'
            }
        },
        {
            name: '导出',
            value: 'export',
            operationId: 'export',
            lang: 'layout.btns.batchExport',
            event: 'batch-export',
            id: 'btn_g_gray',
            plain: true,
            animation: true,
            interface: {
                name: 'batch-out'
            }
        },
        {
            name: '筛选器',
            value: 'filter',
            lang: 'layout.btns.filters',
            event: 'filter',
            class: 'right',
            isValidatePermisssion: true,
            type: 'primary',
            interface: {
                name: 'filter'
            }
        }
        // {
        //   name: '表头配置',
        //   value: 'tabelheaderConfig',
        //   lang: 'layout.btns.tabelheaderConfig',
        //   event: 'showTabelheaderConfig',
        //   id: 'btn_g_gray',
        //   plain: true,
        //   class: 'right',
        //   interface: {
        //     name: 'filter'
        //   }
        // }
    ],
    InputConfig: {
        placeholder: 'form.placeholder.channelPlaceholder',
        long: true,
        prefixIcon: 'el-icon-search'
    },
    tableHeader: [],
    formList: [
        {
            label: '渠道',
            en: 'Channel Number',
            lang: 'channelOrganization.list.filter.channelIdList',
            value: 'channelIdList',
            type: 'highSearch',
            linkValue: 'channelFilterParam',
            highSearchConfig: {
                dialogSearchConfig: channelSearchConfig,
                apiUrl: commonApiUrl.channelFuzzy,
                requestExtend: {
                    channelType: 0
                }
            },
            setLength: 12
        },
        {
            label: '制单用户',
            en: 'Making The User',
            lang: 'channelOrganization.list.filter.createdBy',
            value: 'createdBy',
            type: 'filter',
            fuzzyConfig: {
                apiUrl: commonApiUrl.userFuzzy,
                multiple: true
            },
            setLength: 12
        },
        {
            label: '制单日期',
            value: 'createdTime',
            en: 'Prepare Date',
            lang: 'channelOrganization.list.filter.createdTime',
            type: 'datePick',
            setLength: 12,
            config: {
                type: 'daterange',
                valueFormat: 'yyyy-MM-dd'
            }
        },
        {
            label: '修改用户',
            en: 'Modify The User',
            lang: 'commonWord.updatedByList',
            value: 'updatedByList',
            type: 'filter',
            fuzzyConfig: {
                apiUrl: commonApiUrl.userFuzzy,
                multiple: true
            },
            setLength: 12
        },
        {
            label: '修改时间',
            value: 'updatedTime',
            en: 'Modification Time',
            lang: 'channelOrganization.list.filter.updatedTime',
            type: 'datePick',
            setLength: 12,
            config: {
                type: 'daterange',
                valueFormat: 'yyyy-MM-dd'
            }
        },
        {
            label: '审核用户',
            en: 'Review The User',
            lang: 'channelOrganization.list.filter.checkByList',
            value: 'checkByList',
            type: 'filter',
            fuzzyConfig: {
                apiUrl: commonApiUrl.userFuzzy,
                multiple: true
            },
            setLength: 12
        },
        {
            label: '审核时间',
            value: 'checkTime',
            en: 'Audit Date',
            lang: 'channelOrganization.list.filter.checkTime',
            type: 'datePick',
            setLength: 12,
            config: {
                type: 'daterange',
                valueFormat: 'yyyy-MM-dd'
            }
        },
        {
            label: '作废用户',
            en: 'Invalid User',
            lang: 'channelOrganization.list.filter.cancelByList',
            value: 'cancelByList',
            type: 'filter',
            fuzzyConfig: {
                apiUrl: commonApiUrl.userFuzzy,
                multiple: true
            },
            setLength: 12
        },
        {
            label: '作废时间',
            value: 'cancelTime',
            en: 'Invalid Time',
            lang: 'channelOrganization.list.filter.cancelTime',
            type: 'datePick',
            setLength: 12,
            config: {
                type: 'daterange',
                valueFormat: 'yyyy-MM-dd'
            }
        },
        {
            label: '状态',
            value: 'statusList',
            matchSelectKey: 'statusList',
            en: 'State',
            lang: 'channelOrganization.list.filter.status',
            type: 'select',
            setLength: 12,
            config: {
                multiple: true
            },
            options: [
                {
                    label: '未审核',
                    value: '0'
                },
                {
                    label: '已审核',
                    value: '1'
                },
                {
                    label: '反审核',
                    value: '2'
                },
                {
                    label: '已注销',
                    value: '3'
                }
            ]
        },
        {
            label: '手机号',
            value: 'linkManMobile',
            en: 'linkManMobile',
            lang: 'channelOrganization.list.filter.linkManMobile',
            type: 'text',
            setLength: 12,
            rules: [
                {
                    message: '请输入正确的手机号码',
                    trigger: 'change',
                    pattern: /(^1[3|5|8][0-9]{9}$)/
                }
            ]
        },
        {
            label: '经营品类',
            value: 'commodityCategoryIdList',
            en: 'commodityCategoryIdList',
            matchSelectKey: 'commodityCategorySettingList',
            lang: 'channelOrganization.list.filter.commodityCategoryIdList',
            type: 'cascader',
            setLength: 12
        },
        {
            label: '渠道等级',
            value: 'gradeId',
            en: 'gradeId',
            lang: 'channelOrganization.list.filter.gradeId',
            type: 'select',
            matchSelectKey: 'gradeList',
            config: {
                multiple: false
            },
            setLength: 12
        }
    ]
};

export const detailConfig: DetailComponentsConfig = {
    btns: [
        {
            name: '新建单据',
            value: 'add',
            hiddenIcon: true,
            icon: 'el-icon-plus',
            operationId: 'create',
            lang: 'operationGroup.btns.addChannel',
            plain: true,
            id: 'btn_g_d_blue'
        },
        {
            name: '删除',
            value: 'delete',
            svgIcon: 'rbp-operate_delete',
            operationId: 'delete',
            type: 'text',
            lang: 'operationGroup.btns.delete',
            interface: {
                apiUrl: apiUrl.delChannel,
                params: []
            }
        },
        {
            name: '修改',
            value: 'edit',
            svgIcon: 'rbp-operate_edit',
            operationId: 'modify',
            type: 'text',
            lang: 'operationGroup.btns.edit'
        },
        {
            name: '取消',
            value: 'cancel',
            svgIcon: 'rbp-operate_cancel',
            lang: 'operationGroup.btns.cancel',
            type: 'text',
            isValidatePermisssion: true
        },
        {
            name: '保存',
            value: 'save',
            svgIcon: 'rbp-operate_save',
            lang: 'operationGroup.btns.save',
            type: 'text',
            isValidatePermisssion: true
        },
        {
            name: '审核',
            value: 'audit',
            svgIcon: 'rbp-operate_check',
            lang: 'operationGroup.btns.audit',
            type: 'text',
            operationId: 'check',
            interface: {
                apiUrl: apiUrl.singleAuditChannel
                // params: 'single'
            }
        },
        {
            name: '反审核',
            value: 'unaudit',
            svgIcon: 'rbp-operate_recheck',
            lang: 'operationGroup.btns.unaudit',
            type: 'text',
            operationId: 'uncheck',
            interface: {
                apiUrl: apiUrl.singleUnAuditChannel
                // params: 'single'
            }
        },
        {
            name: '恢复',
            value: 'restore',
            operationId: 'recovery',
            svgIcon: 'rbp-operate_restore',
            lang: 'operationGroup.btns.restore',
            type: 'text',
            interface: {
                apiUrl: apiUrl.restore
                // params: 'string'
            }
        },
        {
            name: '作废',
            value: 'invalid',
            svgIcon: 'rbp-operate_cancellation',
            lang: 'operationGroup.btns.invalid',
            type: 'text',
            operationId: 'invalid',
            interface: {
                apiUrl: apiUrl.singleInvoidChannel
                // params: 'single'
            }
        },
        {
            name: '导入',
            value: 'import',
            svgIcon: 'rbp-operate_import',
            lang: 'operationGroup.btns.import',
            type: 'text',
            operationId: 'import'
        },
        {
            name: '导出',
            value: 'export',
            svgIcon: 'rbp-operate_export',
            lang: 'operationGroup.btns.export',
            type: 'text',
            operationId: 'export'
        },
        // {
        //   name: '打印',
        //   value: 'print',
        //   svgIcon: 'rbp-operate_print',
        //   lang: 'operationGroup.btns.print',
        //   type: 'text',
        //   operationId: 'print'
        // },
        {
            name: '上一个',
            value: 'prev',
            svgIcon: 'rbp-operate_previous',
            lang: 'operationGroup.btns.prev',
            type: 'text',
            class: 'prev-btn',
            isValidatePermisssion: true
        },
        {
            name: '下一个',
            value: 'next',
            svgIcon: 'rbp-operate_next',
            lang: 'operationGroup.btns.next',
            type: 'text',
            isValidatePermisssion: true
        }
    ],
    formList: [
        {
            label: '渠道编号',
            value: 'code',
            en: 'Channel Number',
            lang: 'channelOrganization.detail.formList.code',
            type: 'input',
            rules: [{ required: true, message: '请输入渠道编号', trigger: 'change' }]
        },
        {
            label: '渠道名称',
            value: 'fullName',
            en: 'Channel name',
            lang: 'channelOrganization.detail.formList.fullName',
            type: 'input',
            rules: [{ required: true, message: '请输入渠道名称', trigger: 'change' }]
        },
        {
            label: '渠道简称',
            value: 'name',
            en: 'abbreviation',
            lang: 'channelOrganization.detail.formList.name',
            type: 'input',
            config: {
                moreLanguage: true
            }
        },
        {
            label: '建档日期',
            value: 'buildDate',
            en: 'Document Date',
            lang: 'channelOrganization.detail.formList.buildDate',
            type: 'datePick',
            rules: [{ required: true, message: '请输入制单日期', trigger: 'change' }],
            config: {
                valueFormat: 'yyyy-MM-dd'
            }
        }
    ]
};

export const tabsConfig: ChannelDetail = {
    channelProperties: [
        {
            label: '区域',
            value: 'area',
            en: 'Area',
            lang: 'channelOrganization.tabs.channelProperties.formList.area',
            type: 'cascader',
            matchSelectKey: 'areaTreeList',
            setLength: 12,
            cascaderConfig: ['nation', 'region', 'province', 'city', 'county'],
            options: [],
            config: {
                size: 'mini'
            }
        },
        {
            label: '详细地址',
            value: 'address',
            en: 'Detailed Address',
            lang: 'channelOrganization.tabs.channelProperties.formList.address',
            type: 'input',
            setLength: 12
        },
        {
            label: '组织架构',
            value: 'organization',
            en: 'Organizational Structure',
            matchSelectKey: 'organizationTreeList',
            lang: 'channelOrganization.tabs.channelProperties.formList.organization',
            type: 'cascader',
            setLength: 12,
            cascaderConfig: ['organization1', 'organization2', 'organization3', 'organization4', 'organization5'],
            options: [],
            config: {
                size: 'mini'
            }
        },
        {
            label: '品牌',
            value: 'brandIdList',
            en: 'Brand',
            lang: 'channelOrganization.tabs.channelProperties.formList.brandId',
            type: 'select',
            matchSelectKey: 'brandList',
            setLength: 12,
            config: {
                multiple: true
                // showItemNumber: 3
            },
            options: [],
            refreshKey: 'brand',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '上级渠道',
            value: 'parentChannelId',
            en: 'The Superior Channels',
            lang: 'channelOrganization.tabs.channelProperties.formList.parentChannelId',
            matchSelectKey: 'parentChannelList',
            type: 'select',
            setLength: 6,
            options: []
        },
        {
            label: '分公司',
            value: 'branchCompanyId',
            en: 'Filiale',
            lang: 'channelOrganization.tabs.channelProperties.formList.branchCompanyId',
            type: 'select',
            setLength: 6,
            options: [],
            matchSelectKey: 'branchCompanyList',
            refreshKey: 'branchCompany',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '渠道等级',
            value: 'gradeId',
            en: 'Channel Level',
            lang: 'channelOrganization.tabs.channelProperties.formList.gradeId',
            type: 'select',
            setLength: 6,
            options: [],
            matchSelectKey: 'gradeList',
            refreshKey: 'channelGrade',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '渠道业态',
            value: 'businessFormatId',
            en: 'Channel Forms',
            lang: 'channelOrganization.tabs.channelProperties.formList.businessFormatId',
            type: 'select',
            matchSelectKey: 'businessFormatList',
            setLength: 6,
            options: [],
            refreshKey: 'channelBusinessFormat',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '经营性质',
            value: 'businessNatureList',
            en: 'Nature of operation',
            lang: 'channelOrganization.tabs.channelProperties.formList.businessNatureList',
            type: 'select',
            setLength: 6,
            options: [],
            refreshKey: 'channelBusinessNature',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '结算方式',
            value: 'balanceTypeId',
            en: 'Clearing Form',
            lang: 'channelOrganization.tabs.channelProperties.formList.balanceTypeId',
            type: 'select',
            setLength: 6,
            options: [],
            matchSelectKey: 'balanceTypeList',
            refreshKey: 'channelbalanceType',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '零售吊牌价类型',
            value: 'retailTagPriceTypeId',
            en: 'Type of retail tag price',
            lang: 'channelOrganization.tabs.channelProperties.formList.retailTagPriceTypeId',
            type: 'select',
            setLength: 6,
            options: [],
            matchSelectKey: 'tagPriceTypeList',
            refreshKey: 'tagPriceType',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '分销吊牌价类型',
            value: 'saleTagPriceTypeId',
            en: 'Distribution tag price type',
            lang: 'channelOrganization.tabs.channelProperties.formList.saleTagPriceTypeId',
            type: 'select',
            setLength: 6,
            options: [],
            matchSelectKey: 'tagPriceTypeList',
            refreshKey: 'tagPriceType',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '销售范围',
            value: 'saleRangeId',
            en: 'saleRangeId',
            lang: 'channelOrganization.tabs.channelProperties.formList.saleRangeId',
            type: 'select',
            setLength: 6,
            options: [],
            matchSelectKey: 'salesAreaList'
        },
        {
            label: '联系人',
            value: 'linkMan',
            en: 'linkMan',
            lang: 'channelOrganization.tabs.channelProperties.formList.linkMan',
            type: 'text',
            setLength: 6
        },
        {
            label: '联系人电话',
            value: 'linkManMobile',
            en: 'linkManMobile',
            lang: 'channelOrganization.tabs.channelProperties.formList.linkManMobile',
            type: 'text',
            setLength: 6,
            rules: [
                {
                    message: '请输入正确的手机号码',
                    trigger: 'change',
                    pattern: /(^1[3|5|8][0-9]{9}$)/
                }
            ]
        }
    ],
    financialInformation: [
        {
            label: '资金号',
            value: 'fundAccountId',
            en: 'Account Number Payable',
            lang: 'channelOrganization.tabs.financialInformation.formList.fundAccountId',
            type: 'select',
            setLength: 6,
            matchSelectKey: 'fundAccountList',
            options: [],
            refreshKey: 'fundAccount',
            refreshAPI: '/information/systemDictionary/option/refresh'
        }
    ],
    mallField: [
        {
            label: '经营品类',
            value: 'channelCommodityCategoryList',
            en: 'commodityCategoryIdList',
            matchSelectKey: 'commodityCategorySettingList',
            lang: 'channelOrganization.tabs.mallField.commodityCategoryIdList',
            type: 'cascader',
            setLength: 12
        },
        {
            label: '进货最低最高价',
            value: 'MinimumMaximumPurchasePrice',
            en: 'Minimum Maximum Purchase Price',
            lang: 'channelOrganization.tabs.mallField.MinimumMaximumPurchasePrice',
            type: '',
            setLength: 12
        },
        {
            label: '营业执照',
            value: 'businessLicense',
            en: 'business License',
            lang: 'channelOrganization.tabs.mallField.businessLicense',
            type: '',
            height: 'unset',
            setLength: 6
        },
        {
            label: '主营商品图片',
            value: 'mainCommodityList',
            en: 'main CommodityList',
            lang: 'channelOrganization.tabs.mallField.mainCommodityList',
            type: '',
            height: 'unset',
            setLength: 6
        }
    ],
    salePolicy: [
        {
            label: '销售类别',
            value: 'priceTypeId',
            en: 'Sales category',
            lang: 'channelOrganization.tabs.salePolicy.priceTypeId',
            type: 'select',
            matchSelectKey: 'priceTypeList',
            options: [],
            refreshKey: 'priceType',
            refreshAPI: '/information/systemDictionary/option/refresh'
        },
        {
            label: '折扣',
            value: 'discount',
            en: 'Discount',
            lang: 'channelOrganization.tabs.salePolicy.discount',
            type: 'number'
        }
    ],
    address: [
        {
            label: '默认',
            value: 'defaultFlag',
            en: 'Default',
            width: '60px',
            type: 'radio',
            align: 'left',
            lang: 'channelOrganization.tabs.address.defaultFlag'
        },
        {
            label: '国家/地区',
            value: 'nation',
            en: 'nation',
            type: 'select',
            width: '90px',
            lang: 'channelOrganization.tabs.address.nation',
            require: true
        },
        {
            label: '州/省/地区',
            value: 'province',
            en: 'province',
            type: 'select',
            width: '90px',
            lang: 'channelOrganization.tabs.address.province',
            require: true
        },
        {
            label: '市',
            value: 'city',
            en: 'city',
            type: 'select',
            width: '90px',
            lang: 'channelOrganization.tabs.address.city',
            require: true
        },
        {
            label: '县/区',
            value: 'county',
            en: 'county',
            type: 'select',
            width: '90px',
            lang: 'channelOrganization.tabs.address.county'
        },
        {
            label: '详细地址',
            value: 'address',
            en: 'Address',
            type: 'input',
            lang: 'channelOrganization.tabs.address.address',
            require: true
        },
        {
            label: '联系人',
            value: 'contactsPerson',
            en: 'Contacts Person',
            type: 'input',
            width: '90px',
            lang: 'channelOrganization.tabs.address.contactsPerson',
            require: true
        },
        {
            label: '邮政编码',
            value: 'postCode',
            en: 'Postal Code',
            type: 'input',
            width: '90px',
            lang: 'channelOrganization.tabs.address.postCode'
        },
        {
            label: '手机号码',
            value: 'mobile',
            en: 'Telphone',
            type: 'number',
            lang: 'channelOrganization.tabs.address.mobile',
            require: true
        }
    ],
    anchorConfig: [
        {
            label: '渠道属性',
            // value: 'ChannelProperties',
            value: 'channelProperties',
            en: 'Channel Properties',
            lang: 'channelOrganization.tabs.anchorConfig.fields.channelProperties',
            ref: 'channelProperties'
        },
        {
            label: '商城字段',
            // value: 'ChannelProperties',
            value: 'mallField',
            en: 'mall Field',
            lang: 'channelOrganization.tabs.anchorConfig.fields.mallField',
            ref: 'mallField'
        },
        {
            label: '财务信息',
            // value: 'financialInformation',
            value: 'channel_page_finance',

            en: 'Financial Information',
            // lang: 'channelOrganization.tabs.anchorConfig.fields.financialInformation',
            lang: 'channelOrganization.tabs.anchorConfig.fields.channel_page_finance',

            ref: 'financialInformation',
            isValidatePermisssion: true
        },
        // {
        //   label: '销售政策',
        //   // value: 'salePolicy',
        //   value: 'channel_page_sale_policy',
        //   en: 'sale Policy',
        //   // lang: 'channelOrganization.tabs.anchorConfig.fields.salePolicy',
        //   lang: 'channelOrganization.tabs.anchorConfig.fields.channel_page_sale_policy',
        //   ref: 'salePolicy'
        // },
        {
            label: '收货地址',
            value: 'address',
            en: 'Shipping address',
            lang: 'channelOrganization.tabs.anchorConfig.fields.address',
            ref: 'address'
        },
        {
            label: '控制选项',
            value: 'channel_page_setting',
            en: 'setting Options',
            lang: 'channelOrganization.tabs.anchorConfig.fields.channel_page_setting',
            ref: 'settingOptions',
            isValidatePermisssion: true

            // fixedIndex: 'last'
        }
    ]
};
export const initFormData = () => {
    // 数据字典
    const detailData = {
        channel: {
            // form部分
            code: '', // 渠道编号
            fullName: '', // 渠道名称
            name: '', // 渠道简称
            buildDate: Tools.getCurrentData(false), // 制单日期

            // 渠道属性部分
            area: [], // 区域
            nation: '', // 国家
            region: '', // 大区
            province: '', // 省份
            city: '', // 城市
            county: '', // 区/县

            organization: [], // 组织架构
            organization1: '', // 组织架构1
            organization2: '', // 组织架构2
            organization3: '', // 组织架构3
            organization4: '', // 组织架构4
            organization5: '', // 组织架构5

            brandIdList: [], // 品牌
            parentChannelId: '', // 上级渠道
            branchCompanyId: '', // 分公司
            gradeId: '', // 渠道等级
            businessFormatId: '', // 渠道业态
            balanceTypeId: '', // 结算方式
            tagPriceTypeId: '', // 吊牌价类型
            salesAreaId: '', // 销售区域

            // 财务信息部分
            receivableChannelId: '', // 应收户口编号
            payableChannelId: '', // 应付户口编号
            legalPersonId: '', // 法人
            credit: '', // 信用额度
            bankCard: '' // 银行卡号
        },
        languageMap: {},
        customFieldMap: {},
        channelReceiveInfoList: []
    };
    return detailData;
};

// 这里定义用途 用作 国际化 的数据
export const channelOrganization = {
    list: listConfig,
    detail: detailConfig,
    tabs: tabsConfig
};
